import java.util.List;

public class InsertCommand implements Command {

    private final Genome genome;
    private final int genomeIndex;
    private final int position;
    private final List<Integer> blocks;

    public InsertCommand(int genomeIndex, Genome genome, int position, List<Integer> blocks) {
        this.genomeIndex = genomeIndex;
        this.genome = genome;
        this.position = position;
        this.blocks = blocks;
    }

    @Override
    public void execute() throws ParametersException {
        genome.insert(position, blocks);
    }

    @Override
    public void undo() throws ParametersException {
        genome.delete(position, position + blocks.size());
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("insert ");
        stringBuilder.append(genomeIndex);
        stringBuilder.append(" ");
        stringBuilder.append(position);
        for(int block : blocks) {
            stringBuilder.append(" ");
            stringBuilder.append(block);
        }
        return stringBuilder.toString();
    }
}
